package com.gitee.wsl.math.interpolator


import com.gitee.wsl.mathematics.interpolator.Interpolate
import com.gitee.wsl.mathematics.interpolator.UnInterpolatorFun
import com.gitee.wsl.mathematics.interpolator.Percent
import kotlin.time.ExperimentalTime
import kotlin.time.Instant

 @OptIn(ExperimentalTime::class)
 fun Interpolate.Companion.interpolateDate(start: Instant, end: Instant): Interpolate<Instant> {
    val range = end - start
    return Interpolate{ percent -> start + (range * percent.value) }
}

 @OptIn(ExperimentalTime::class)
 fun Interpolate.Companion.uninterpolateDate(start: Instant, end: Instant): UnInterpolatorFun<Instant> {
    val range = end - start
    val nullRange = (start == end)
    return { date ->
        if (nullRange) Percent(.0)
        else Percent((date - start) / range)
    }
}
